package com.zhang.spark_2.com.zhang.core.acc

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

/**
 * @title:
 * @author: zhang
 * @date: 2022/2/16 18:36 
 */
object Spark01_Acc {

  def main(args: Array[String]): Unit = {

    //TODO 获取环境
    val conf = new SparkConf().setMaster("local").setAppName("WordCount")
    val sc = new SparkContext(conf);

    val list: RDD[Int] = sc.makeRDD(List(1, 2, 3, 4), 2)

    var sum = sc.longAccumulator("sum")

    list.foreach(
      num => sum.add(num)
    )
    println(sum.value)



    sc.stop()

  }
}
